package DynamicProgramming;
/*
 * 打家劫舍 III
 */
import BinaryTree.init.TreeNode;

public class lc337 {

    public int rob(TreeNode root) {
        int[] res = robtree(root);
        return Math.max(res[0], res[1]);
    }
    public int[] robtree(TreeNode cur) {
        if (cur == null) return new int[]{0, 0};
        int[] leftdp = robtree(cur.left);
        int[] rightdp = robtree(cur.right);
        int v1 = Math.max(leftdp[0], leftdp[1]) + Math.max(rightdp[0], rightdp[1]);
        int v2 = cur.val + leftdp[0] + rightdp[0];
        return new int[]{v1, v2};
    }

}
